package com.gitee.kamismile.stone.basic.data.infrastructure.repository.handler.r2.convert;



import net.sf.json.JSONObject;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;

@ReadingConverter
public class JsonObjectConverter implements Converter<String,JSONObject> {

    @Override
    public JSONObject convert(String sqlJson) {
        if (null != sqlJson) {
            return JSONObject.fromObject(sqlJson);
        }
        return null;
    }

    @WritingConverter
    public static class JsonObjectToStringConverter implements Converter<JSONObject,String> {

        public String convert(JSONObject jsonData) {
            if (null != jsonData) {
                return jsonData.toString();
            }
            return null;
        }
    }
}

